package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pkx.guide.common.annotation.ORpose;
import com.baomidou.mybatisplus.core.metadata.IPage;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import com.pkx.guide.common.annotation.Log;
import com.pkx.guide.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>

<#assign keyPropertyType="">
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign keyPropertyType="${field.propertyType}">
    </#if>
</#list>
/**
 * ${table.comment!} 控制器
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Tag(name = "${table.comment!}")
@Slf4j
@ORpose
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @Operation(summary = "${table.comment!}分页列表")
    @GetMapping("/page")
    public IPage<${entity}> page(Page page, ${entity} ${entity?uncap_first}) {
        return ${table.serviceName?uncap_first}.pageList(page,${entity?uncap_first});
    }

    @Operation(summary = "${table.comment!}列表")
    @GetMapping("/list")
    public List<${entity}> list(${entity} ${entity?uncap_first}) {
        return ${table.serviceName?uncap_first}.listByEntity(${entity?uncap_first});
    }

    @Operation(summary = "${table.comment!}详情")
    @GetMapping(value = "/{id}")
    public ${entity} selectById(@PathVariable("id") ${keyPropertyType} id) {
        return ${table.serviceName?uncap_first}.selectById(id);
    }

    @Operation(summary = "${table.comment!}新增")
    @PostMapping("/")
    @Log(title = "${table.comment!}", businessType = BusinessType.INSERT)
    public Boolean add(@RequestBody ${entity} ${entity?uncap_first}) {
        return ${table.serviceName?uncap_first}.save${entity}(${entity?uncap_first});
    }

    @Operation(summary = "${table.comment!}修改")
    @PutMapping("/")
    @Log(title = "${table.comment!}", businessType = BusinessType.UPDATE)
    public Boolean modify(@RequestBody ${entity} ${entity?uncap_first}) {
        return ${table.serviceName?uncap_first}.modify(${entity?uncap_first});
    }

    @Operation(summary = "${table.comment!}删除(单个条目)")
    @DeleteMapping(value = "/{id}")
    @Log(title = "${table.comment!}", businessType = BusinessType.DELETE)
    public Boolean deleteById(@PathVariable("id") ${keyPropertyType} id) {
        return ${table.serviceName?uncap_first}.deleteById(id);
    }
}
</#if>
